package net.lab1024.sa.admin.module.app.user;

import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
import net.lab1024.sa.admin.module.app.user.domain.UserAddForm;
import net.lab1024.sa.admin.module.app.user.domain.UserQueryForm;
import net.lab1024.sa.admin.module.app.user.domain.UserUpdateForm;
import net.lab1024.sa.admin.module.app.user.domain.UserVO;
import net.lab1024.sa.admin.module.system.login.domain.RequestEmployee;
import net.lab1024.sa.admin.util.AdminRequestUtil;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.Valid;

/**
 * app小程序用户 Controller
 *
 * @Author M
 * @Date 2024-10-18 20:45:17
 * @Copyright Transmute实验室
 */

@RestController
@Tag(name = AdminSwaggerTagConst.App.APP_USER)
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @Operation(summary = "分页查询 @author M")
    @PostMapping("/user/queryPage")
    public ResponseDTO<PageResult<UserVO>> queryPage(@RequestBody UserQueryForm queryForm) {
        RequestEmployee requestUser = AdminRequestUtil.getRequestUser();
        return ResponseDTO.ok(userService.queryPage(queryForm, requestUser));
    }

    @Operation(summary = "添加 @author M")
    @PostMapping("/user/add")
    public ResponseDTO<String> add(@RequestBody @Valid UserAddForm addForm) {
        return userService.add(addForm);
    }

    @Operation(summary = "更新 @author M")
    @PostMapping("/user/update")
    public ResponseDTO<String> update(@RequestBody @Valid UserUpdateForm updateForm) {
        return userService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author M")
    @PostMapping("/user/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return userService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author M")
    @GetMapping("/user/delete/{userId}")
    public ResponseDTO<String> batchDelete(@PathVariable Long userId) {
        return userService.delete(userId);
    }

    @Operation(summary = "重置密码 @author M")
    @PostMapping("/user/resetPassword/{userId}")
    public ResponseDTO<String> resetPassword(@PathVariable Long userId) {
        return userService.resetPassword(userId);
    }
}
